﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Antu.DataAccess;
using EluZSProvider;
using Antu.Core.Services;

namespace WebSys.UI.Skins.ZhengShou.SFManage
{
    public partial class office_admintools : System.Web.UI.Page
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");

        TextBox TextBox1;
        protected void Page_Load(object sender, EventArgs e)
        {
            InitControl();

        }

        protected void InitControl()
        {
            TextBox1 = (TextBox)FindControl("TextBox1");
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
         
            string iidstr = TextBox1.Text.Trim();
            if (!string.IsNullOrEmpty(iidstr))
            {
                string sql = "select count(*) from st_instance where iid='" + iidstr + "' and status=2";
                int havecount = Convert.ToInt32(_EluZSDataProvider.GetString(sql));
                if (havecount > 0)
                {
                    sql = @"insert into st_work_item
select iid,wiid,prev_wiid,userid,step,'0',ACCEPTED_TIME,'0',null,null,null,null,null,null,
SENDSTEP,SENDUSERID,null,'0',null,null,null,null from st_work_item_hist t where iid='" + iidstr + @"'
and wiid=(select max(wiid) from st_work_item_hist t where iid='" + iidstr + @"')";
                    _EluZSDataProvider.RunSqlNon(sql);
                    sql = @"delete from st_work_item_hist t where iid='" + iidstr + @"'
and wiid=(select max(wiid) from st_work_item_hist t where iid='" + iidstr + @"') ";
                    _EluZSDataProvider.RunSqlNon(sql);

                    //            sql = @"select * from st_work_item_stack t where iid='" + iidstr + @"'
                    //and wiid=(select max(wiid) from st_work_item_stack t where iid='" + iidstr + @"')";
                    //            ida.RunSql(sql);
                    sql = "update st_instance t  set status=1 where iid='" + iidstr + "'";
                    _EluZSDataProvider.RunSqlNon(sql);

                    Response.Write("<script>alert('操作后退成功!');history.back();</script>");
                    Response.End();
                }
                else
                {
                    Response.Write("<script>alert('该案子没有办结!');history.back();</script>");
                    Response.End();
                }
            }
            else
            {
                Response.Write("<script>alert('IID为空!');history.back();</script>");
                Response.End();
            }
        }
    }
}